<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.beaut.project.util.FlowUtility" %>
<%@ include file="/public/header.jsp"%>
<%
String gd_id = request.getParameter("gd_id") == null ? "" : request.getParameter("gd_id");
String type = request.getParameter("type") == null ? "" : request.getParameter("type");
String gd_content_id = request.getParameter("gd_content_id") == null ? "" : request.getParameter("gd_content_id");

%>
<html>
	<head>
		<title>补采购单</title>
	</head>
	<script type="text/javascript">
		$(function(){
			$("#searchValue").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch();
		       	} 
			});
			$("#dept_id").combotree({
				url:'<%=contextPath %>/springMVC/group/listDepartment',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					doSearch();
				}
			});
			$("#table").datagrid({
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath %>/springMVC/gd/listPageGDSupplierApply?gd_id=<%=gd_id%>&type=<%=type%>&statusFlag=3',
				fitColumns:true,
				rownumbers:true,
				idField:'id',
				nowrap:false,
				frozenColumns:[[
				    {field:'id',hidden:true}
				]],
				columns:[[
					{title:'申请日期',field:'operation_date',width:100,align:'center'},
					{title:'工单编号',field:'gd_code',width:100,align:'center'},
					{title:'工单名称',field:'gd_name',width:150,align:'center'},
					{title:'申请部门',field:'dept_name',width:100,align:'center'},
					{title:'申请人',field:'person',width:100,align:'center'},
					{title:'摘要',field:'remark',width:200,align:'center'},
					{title:'余料入工余',field:'edit',width:100,align:'center',formatter:function(value,rowData,rowIndex){
                    	return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-undo' title='入工余' onclick=\"javascript:returnMyGd('"+rowData.id+"');\"/>";
	
					}}
				]],
				view: detailview,
				detailFormatter:function(index,row){
					return '<div style="padding:2px"><table class="ddv"></table></div>';
				},
				onExpandRow: function(index,row){
					var supplier_apply_id = row.id;
					var ddv = $(this).datagrid('getRowDetail',index).find('table.ddv');
					 ddv.datagrid({
						title:'明细',
						url:'<%=contextPath %>/springMVC/gd/listGDSupplierApplyDetail?gd_id=<%=gd_id%>&gd_content_id=<%=gd_content_id%>&supplier_apply_id='+supplier_apply_id,
						loadMsg:'正在加载数据，请稍后......',
						fitColumns:true,
						rownumbers:true,
						columns:[[
							{title:'厂家',field:'supplier',width:200,align:'center'},
							{title:'产品编号',field:'code',width:100,align:'center'},
							{title:'产品名称',field:'name',width:200,align:'center'},
							{title:'规格/型号',field:'format_type',width:200,align:'center'},
							{title:'单位',field:'unit_name',width:100,align:'center'},
							{title:'申请数量',field:'apply_num',width:100,align:'center'},
							{title:'领用数量',field:'num',width:100,align:'center'}
						]],
					 	onResize:function(){
					        $('#table').datagrid('fixDetailRowHeight',index);
					    },
					 	onLoadSuccess:function(){
					       setTimeout(function(){
					         $('#table').datagrid('fixDetailRowHeight',index);
					       },0);
					   }
					 });
					 $('#table').datagrid('fixDetailRowHeight',index);
				},
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				}
			});
		});
		function showPurchase(purchase_id){
			openDialogResize("<%=contextPath %>/springViews/warehouse/addOrEditSupplierPurchase.jsp?isShow=1&purchase_id="+purchase_id,1000, 800);
		}
		function doSearch()
		{
			var searchValueTwo = $('#searchValueTwo').val();
			$('#table').datagrid('load',{
				searchValueTwo:searchValueTwo
				
			});
		}
		function returnMyGd(apply_id){
			openDialogResize("<%=contextPath %>/springViews/warehouse/returnMydb.jsp?business_type=3&apply_id="+apply_id,1000, 800);
		}
		function doSearch()
		{
			var dept_id = $('#dept_id').combotree('getValue');
			var searchValueTwo = $('#searchValueTwo').val();
			var searchValue = $('#searchValue').val();
			var start_time=$('#start_time').datebox('getValue');  
			var end_time=$('#end_time').datebox('getValue');  
			$('#table').datagrid('load',				
				{
					searchValueTwo:searchValueTwo,
					dept_id:dept_id,
					searchValue:searchValue,
					start_time:start_time,
					end_time:end_time
				}
			);
		}
	</script>
	<body style="height: 97%">
		<div id="table" data-options="fit:true,toolbar:'#tb'" ></div>
		<div id="tb" style="padding:3px;height:auto">
			<div align="right">
				 开始时间：<input id="start_time" name="start_time" class="easyui-datebox"  style="width:90px" />&nbsp;&nbsp;&nbsp;结束时间：<input id="end_time" name="end_time" class="easyui-datebox" style="width:90px" />
 				选择部门：<input  id="dept_id" name="dept_id" class="easyui-combotree">  
				工单编号/名称：<input id="searchValue" name="searchValue" style="width:100px" title="工单编号/名称" placeholder="工单编号/名称"/>&nbsp;&nbsp;
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
			</div>
		</div>
		</body>
</html>
